<template>
    <div class="app-container">
        <el-row>
            <!--用户数据-->
            <el-col :span="24" :xs="24">
                <el-form :model="queryParams" ref="queryForm"  :inline="true" v-show="showSearch"
                    label-width="68px">
                    <el-form-item label="任务名称" prop="title">
                        <el-input v-model="queryParams.title" placeholder="请输入任务名称" clearable style="width: 240px"
                            @keyup.enter.native="handleQuery" />
                    </el-form-item>

                    <el-form-item label="鉴定日期">
                        <el-date-picker v-model="dateRange" style="width: 240px" value-format="yyyy-MM-dd" type="daterange"
                            range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
                    </el-form-item>
                    <el-form-item label="鉴定状态" prop="state">
                        <el-select v-model="queryParams.state" placeholder="请选择">
                            <el-option v-for="item in dict.type.JDZT" :key="item.value" :label="item.label" :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="全宗号" prop="qzh">
                        <el-input v-model="queryParams.qzh" placeholder="请输入全宗号" clearable style="width: 240px"
                            @keyup.enter.native="handleQuery" />
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" icon="el-icon-search"  @click="handleQuery">搜索</el-button>
                        <el-button icon="el-icon-refresh"  @click="resetQuery">重置</el-button>
                    </el-form-item>
                </el-form>

                <el-row :gutter="10" class="mb8">
                    <el-col :span="1.5">
                        <el-button type="primary" plain icon="el-icon-plus"  @click="handleDeit()">添加</el-button>
                    </el-col>
                    <el-col :span="1.5">
                        <el-button type="success" plain icon="el-icon-plus"  @click="handleTrack">跟踪</el-button>
                    </el-col>
                    <el-col :span="1.5">
                        <el-button type="danger" plain icon="el-icon-plus"  @click="handlefqjd">发起鉴定</el-button>
                    </el-col>
                    <el-col :span="1.5">
                        <el-button type="danger" plain icon="el-icon-plus"  @click="handlecxjd">撤销鉴定</el-button>
                    </el-col>
                    <el-col :span="1.5">
                        <el-button type="danger" plain icon="el-icon-plus"  @click="handlejdsx">鉴定生效</el-button>
                    </el-col>
                    <el-col :span="1.5">
                        <el-button type="warning" plain icon="el-icon-download"
                            @click="handleExport">导出</el-button>
                    </el-col>
                    <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
                </el-row>
                <el-table v-loading="loading" :data="list" @selection-change="handleSelectionChange"
                    @cell-dblclick="celldblclick" :height="tableHeight" border>
                    <el-table-column type="selection" width="50" align="center" />
                    <el-table-column label="序号" sortable align="center" type="index" />
                    <el-table-column label="操作" align="center" width="380px">
                        <template slot-scope="scope">
                            <el-button type="text"  icon="el-icon-document-remove"
                                @click.native.stop="handleTransferTheFiles(scope.row)"
                                :disabled="scope.row.JIANDINGSTATE != 1 ? true : false">调档</el-button>
                            <el-button type="text"  icon="el-icon-c-scale-to-original"
                                @click.native.stop="handleAssignTask(scope.row)">分配</el-button>
                            <el-button type="text"  icon="el-icon-edit"
                                @click.native.stop="handleDeit(scope.row)"
                                :disabled="scope.row.JIANDINGSTATE != 1 ? true : false">修改</el-button>
                            <el-button type="text"  icon="el-icon-delete"
                                @click.native.stop="handleDel(scope.row)"
                                :disabled="scope.row.JIANDINGSTATE != 1 ? true : false">删除</el-button>
                            <el-button type="text"  icon="el-icon-finished"
                                @click.native.stop="handleCompletedd(scope.row)">调档完成</el-button>
                                <el-button type="text" icon="el-icon-document"
                                @click.native.stop="handleCompleteDetails(scope.row)">详情</el-button>
                        </template>
                    </el-table-column>
                    <el-table-column label="鉴定任务名称" align="center" prop="JIANDINGRENWUNAME" :show-overflow-tooltip="true" />
                    <el-table-column label="任务批次号" align="center" prop="RENWUNO" :show-overflow-tooltip="true" />
                    <el-table-column label="全宗号" align="center" prop="QZH" :show-overflow-tooltip="true" />
                    <el-table-column label="鉴定状态" align="center" prop="JIANDINGSTATE" :show-overflow-tooltip="true">
                        <template slot-scope="scope">
                            <span v-for="(i, idx) in dict.type.JDZT" :key="idx">
                                {{ scope.row.JIANDINGSTATE == i.value ? i.label : '' }}
                            </span>
                        </template>
                    </el-table-column>
                    <el-table-column label="鉴定组组长" align="center" :show-overflow-tooltip="true">
                        <template slot-scope="scope">
                            {{ scope.row.JIANDINGLEADERNAME }}
                        </template>
                    </el-table-column>
                    <el-table-column label="初审人员" align="center" :show-overflow-tooltip="true">
                        <template slot-scope="scope">
                            {{ scope.row.CHUSHENPEOPLENAME }}
                        </template>
                    </el-table-column>
                    <el-table-column label="复审人员" align="center" :show-overflow-tooltip="true">
                        <template slot-scope="scope">
                            {{ scope.row.FUSHENPEOPLENAME }}
                        </template>
                    </el-table-column>
                    <el-table-column label="审定人员" align="center" :show-overflow-tooltip="true">
                        <template slot-scope="scope">
                            {{ scope.row.SHENDINGPEOPLENAME }}
                        </template>
                    </el-table-column>

                    <el-table-column label="鉴定创建日期" align="center" prop="JIANDINGSTARTDATE" width="160">
                        <template slot-scope="scope">
                            {{ scope.row.JIANDINGSTARTDATE }}
                        </template>
                    </el-table-column>

                    <el-table-column label="任务结束日期" align="center" prop="JIANDINGENDDATE" width="160">
                        <template slot-scope="scope" v-if="scope.row.JIANDINGENDDATE">
                            {{ scope.row.JIANDINGENDDATE }}
                        </template>
                    </el-table-column>
                    <el-table-column label="备注" align="center" prop="REMARK" :show-overflow-tooltip="true" />
                </el-table>

                <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
                    :limit.sync="queryParams.pageSize" @pagination="getList" />
            </el-col>
        </el-row>


        <!-- 添加 修改弹窗-->
        <vDeit v-if="deitOpen" :open="deitOpen" :rowInfo="rowInfo" @closeDelDialog="closeDelDialog"
            @submitForm="submitForm"></vDeit>

        <!-- 跟踪 -->
        <vTrack v-if="trackOpen" :open="trackOpen" :rowInfo="rowInfo" @closeDelDialog="closeDelDialog"></vTrack>

        <!-- 详情 -->
        <vDetail v-if="detailOpen" :open="detailOpen" :rowInfo="rowInfo" @closeDelDialog="closeDelDialog"></vDetail>
 <!-- 开放鉴定按钮详情页面 -->
 <jdDetails v-if="jdOpen" :open="jdOpen" :rowInfo="rowInfo" @closeDelDialog="closeDelDialog"></jdDetails>
        <!-- 调档 -->
        <vTransferTheFiles v-if="transferTheOpen" :open="transferTheOpen" :rowInfo="rowInfo"
            @closeDelDialog="closeDelDialog"></vTransferTheFiles>

        <!-- 分配 -->
        <vAssignTasks v-if="assignTasksOpen" :open="assignTasksOpen" :rowInfo="rowInfo" @closeDelDialog="closeDelDialog">
        </vAssignTasks>
    </div>
</template>

<script>

import { kfjdjoblist, deletejob, fqjd, hasfenpeipro, completedd, chexiaojob, jiandingshengxiao,hasupdatepro} from "@/api/archive/archivalAppraisal/bgqx/openArchivesAppraisal"
import estimateTableHeight from '@/mixins/estimateTableHeight';
import vDeit from "@/views/archive/archivalAppraisal/bgqx/openArchivesAppraisal/deit/index.vue" //添加修改弹窗
import vTrack from "@/views/archive/archivalAppraisal/bgqx/openArchivesAppraisal/track/index.vue" //跟踪弹窗
import vDetail from "@/views/archive/archivalAppraisal/bgqx/openArchivesAppraisal/detail/index.vue" //详情弹窗
import vTransferTheFiles from "@/views/archive/archivalAppraisal/bgqx/openArchivesAppraisal/transferTheFiles/index.vue" //调档弹窗
import vAssignTasks from "@/views/archive/archivalAppraisal/bgqx/openArchivesAppraisal/assignTasks/index.vue"
import jdDetails from "@/views/archive/archivalAppraisal/bgqx/openArchivesAppraisal/details/index.vue" //开放鉴定按钮详情
export default {
    archive_Dicts: ['JDZT'],
    mixins: [estimateTableHeight], // 混入方法
    components: {
        vDeit,
        vTrack,
        vDetail,
        vTransferTheFiles,
        vAssignTasks,
        jdDetails
    },
    data() {
        return {
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 表格数据
            list: null,
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                title: undefined,
                starttime: undefined, //开始时间
                endtime: undefined,//结束时间
                state:undefined,//鉴定状态
                qzh:undefined,//全宗号
                order: undefined
            },
            dateRange: [],
            rowInfo: "",
            deitOpen: false,//添加修改弹窗
            trackOpen: false, //跟踪弹窗
            detailOpen: false,//详情弹窗
            jdOpen:false,//开放鉴定按钮详情弹窗
            transferTheOpen: false,//调档弹窗
            assignTasksOpen: false,//分配
            // jiandingstate: [
            //     {
            //         id: 1,
            //         name: "未开始"
            //     }, {
            //         id: 2,
            //         name: "分配任务中"
            //     }, {
            //         id: 3,
            //         name: "初审中"
            //     }, {
            //         id: 4,
            //         name: "待复审"
            //     }, {
            //         id: 5,
            //         name: "复审中"
            //     }, {
            //         id: 6,
            //         name: "审定中"
            //     }, {
            //         id: 7,
            //         name: "审定已完成"
            //     }, {
            //         id: 8,
            //         name: "鉴定完成"
            //     }, {
            //         id: 9,
            //         name: "鉴定撤销"
            //     },
            // ]
        };
    },
    created() {
        this.getList();


    },
    methods: {
        /** 查询列表 */
        getList() {
          if(this.dateRange != null) {
            this.queryParams['starttime']=this.dateRange[0];
            this.queryParams['endtime']=this.dateRange[1];
          } else {
            this.queryParams['starttime']=undefined;
            this.queryParams['endtime']=undefined;
          }
            this.loading = true;
            kfjdjoblist(this.queryParams).then(response => {
                this.list = response.rows;
                this.total = response.total;
                this.loading = false;
            }
            );
        },

        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.dateRange = [];
            this.resetForm("queryForm");
            this.queryParams.deptId = undefined;
            // this.$refs.tree.setCurrentKey(null);
            this.queryParams.pageNum = 1;
            this.getList();
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map(item => item.ID);
            this.single = selection.length != 1;
            this.multiple = !selection.length;
        },

        /** 添加修改按钮操作 */
        handleDeit(row) {
            this.rowInfo = row;
            if(this.rowInfo!=undefined){
            hasupdatepro(row.ID).then(res => {
                if (res.code == "200") {
                    if (res.data) {
                        this.deitOpen = true; //添加修改
                    }else{
                        this.$message({ message:"只有此条任务的创建人才能修改哦!", type: 'warning' })
                    }
                }

            })
        }else{
            this.deitOpen = true; //添加修改 
        }
        },
        /**开放鉴定详情按钮操作**/
        handleCompleteDetails(row){
            this.rowInfo=row;
            this.jdOpen=true;
        },
        /**跟踪按钮操作 */
        handleTrack() {
            if (this.ids.length > 0) {
                if (!this.single) {

                    this.rowInfo = this.ids.toString();
                    this.trackOpen = true;
                } else {
                    this.$message({ message: '只能选择一条跟踪的数据!', type: 'warning' })
                    return false
                }
            } else {
                this.$message({ message: '请选择跟踪的数据!', type: 'warning' })
                return false
            }
        },

        //关闭添加弹窗
        closeDelDialog() {
            // this.rowInfo=[];
            this.deitOpen = false;//添加修改
            this.detailOpen = false; //详情
            this.transferTheOpen = false;//调档
            this.trackOpen = false;//跟踪
            this.assignTasksOpen = false; //分配
            this.jdOpen=false;
            this.getList()
        },

        //添加成功
        submitForm() {
            this.deitOpen = false; //添加修改
            this.getList();
        },
        //双击查看详情
        celldblclick(row, column, cell, event) {
            console.log(event)
            if (event.type === "dblclick") {
                this.rowInfo = row;
                this.detailOpen = true;
            }
        },
        //点击调档事件
        handleTransferTheFiles(row) {
            this.rowInfo = row;
            this.transferTheOpen = true;
        },
        /** 删除按钮操作 */
        handleDel(row) {
            this.$modal.confirm('是否确认删除"' + row.JIANDINGRENWUNAME + '"的数据项？').then(() => {
                deletejob(row.ID).then(res => {
                    this.$modal.msgSuccess(res.msg);
                    this.getList();
                })
            }).catch(() => { });
        },
        //分配
        handleAssignTask(row) {
            if (row.JIANDINGSTATE == '1') {
                this.$message({ message: '调档未完成不允许分配！', type: 'warning' })
                return;
            }
            //当前人是否有分配任务的权限 true是有权限,false没有
            hasfenpeipro(row.ID).then(res => {
                if (res.data) {
                    this.rowInfo = row;
                    this.assignTasksOpen = true;
                } else {
                    this.$message({ message: '只有此任务的鉴定组组长可分配任务！', type: 'warning' })
                }
            })

        },

        //调档完成
        handleCompletedd(row) {
            if (row.JIANDINGSTATE == "1") {
                completedd(row.ID).then(res => {
                    if (res.code == "200") {
                        this.$modal.msgSuccess("调档完成")
                        this.getList();
                    }
                })
            } else {
                this.$message({ message: '已调档完成！', type: 'warning' })
            }
        },
        //发起鉴定
        handlefqjd() {
            if (this.ids.length > 0) {
                if (!this.single) {
                    this.$modal.confirm('是否确认发起鉴定？').then(() => {

                        fqjd(this.ids.toString()).then(res => {
                            this.$modal.msgSuccess(res.msg);
                            this.getList();
                        })

                    }).catch(() => { });


                } else {
                    this.$message({ message: '只能选择一条要鉴定的数据!', type: 'warning' })
                    return false
                }
            } else {
                this.$message({ message: '请选择需要鉴定的数据!', type: 'warning' })
                return false
            }
        },

        //撤销鉴定
        handlecxjd() {
            if (this.ids.length > 0) {
                if (!this.single) {
                    this.$modal.confirm('是否确认撤销鉴定？').then(() => {
                        chexiaojob(this.ids.toString()).then(res => {
                            this.$modal.msgSuccess(res.msg);
                            this.getList();
                        })
                    }).catch(() => { });
                } else {
                    this.$message({ message: '只能选择一条要鉴定的数据!', type: 'warning' })
                    return false
                }
            } else {
                this.$message({ message: '请选择需要鉴定的数据!', type: 'warning' })
                return false
            }
        },
        //鉴定生效
        handlejdsx() {
            if (this.ids.length > 0) {
                if (!this.single) {
                    this.$modal.confirm('是否确认鉴定生效？').then(() => {
                        jiandingshengxiao({
                            jobids: this.ids
                        }).then(res => {
                            this.$modal.msgSuccess(res.msg);
                            this.getList();
                        })
                    }).catch(() => { });

                } else {
                    this.$message({ message: '只能选择一条要鉴定的数据!', type: 'warning' })
                    return false
                }
            } else {
                this.$message({ message: '请选择需要鉴定的数据!', type: 'warning' })
                return false
            }
        },
        /** 导出按钮操作 */
        handleExport() {
            if (!this.multiple) {
                console.log(this.ids,"+++++++++++++")
                this.download('/archive/bgqxidentify/exportjob', {ids:this.ids.toString()}, `bgqx_${new Date().getTime()}.xlsx`)
            } else {
                this.$message({ message: '请选择需要导出的数据!', type: 'warning' })
            }
        },
        /** 导入按钮操作 */
        handleImport() {
            //alert(this.queryParams.deptId);
            if (this.queryParams.deptId == undefined) {
                this.$modal.msgWarning("请选择部门节点！");
                return;
            }
            this.upload.deptId = this.queryParams.deptId;
            this.upload.title = "用户导入";
            this.upload.open = true;
        },
        /** 下载模板操作 */
        importTemplate() {
            this.download('system/user/importTemplate', {
            }, `user_template_${new Date().getTime()}.xlsx`)
        },
        // 文件上传中处理
        handleFileUploadProgress(event, file, fileList) {
            this.upload.isUploading = true;
        },
        // 文件上传成功处理
        handleFileSuccess(response, file, fileList) {
            this.upload.open = false;
            this.upload.isUploading = false;
            this.$refs.upload.clearFiles();
            this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
            this.getList();
        },
        // 提交上传文件
        submitFileForm() {
            this.$refs.upload.submit();
        }
    }
};
</script>


